package com.iyao_app.util;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import com.iyao_app.R;


/**
 * 作者 :  胡家兵
 * 时间 :  2017/11/14.
 */

public class CustomDialog extends Dialog {

    private final TextView mTvContent;
    private final TextView mTvConfirm;
    private boolean isDismiss = true;

    public CustomDialog(@NonNull Context context) {
        super(context, R.style.MyDialog);
        setContentView(R.layout.dialog_custom);
        mTvContent = findViewById(R.id.tv_content);
        mTvConfirm = findViewById(R.id.tv_confirm);
        Window window = getWindow();
        //设置动画效果
        window.setWindowAnimations(R.style.MyDialogAnim);

    }

    public CustomDialog setContent(String content) {
        if (mTvContent != null) {
            mTvContent.setText(content);
        }
        return this;
    }

    public CustomDialog setConfirmText(String title) {
        if (mTvConfirm != null) {
            mTvConfirm.setText(title);
        }
        return this;
    }

    public CustomDialog setOnConfirmClickListener(final View.OnClickListener listener) {
        mTvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null)
                    listener.onClick(v);
                if (isDismiss) {
                    CustomDialog.this.dismiss();
                }
            }
        });

        return this;
    }


    public CustomDialog setConfirmDismiss(boolean isDismiss) {
        this.isDismiss = isDismiss;
        return this;
    }

    public CustomDialog setCanceled(boolean isCancel) {
        this.setCanceledOnTouchOutside(isCancel);
        return this;
    }
}
